package com.fixme4trade.view;


import java.util.List;

import javax.inject.Inject;
import com.fixme4trade.business.ProductBC;
import com.fixme4trade.domain.Product;
import com.fixme4trade.domain.Seller;

import br.gov.frameworkdemoiselle.annotation.Name;
import br.gov.frameworkdemoiselle.annotation.NextView;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractListPageBean;
import br.gov.frameworkdemoiselle.util.Parameter;

@ViewController
//@PreviousView("/public/product_list.xhtml")
@NextView("/public/product_show.xhtml")
public class ProductListByQueryMB extends AbstractListPageBean<Product, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private ProductBC bc;	
	
	@Inject
	@Name("productQuery")
	private Parameter<String> queryParameter;
	
	@Inject
	@Name("sellerId")
	private Parameter<String> sellerIdParam;
		
	private String query;

	@Override
	protected List<Product> handleResultList() {
		String query = queryParameter.getValue();
		System.out.println("PARAMETER = "+query);
		return this.bc.getProductsByQuery(query);
	}		

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {		
		this.query = query;
	}
	
	public String getSellerView(Seller seller) {
		//System.out.println("SellerID ="+sellerIdParam.getValue());
		return "/public/seller_show.xhtml";//sellerId="+sellerIdParam.getValue();
	}
	
	public String goSearch() {
		System.out.println("QUERRY = "+query);
		return "/public/product_list.jsf?productQuery="+getQuery();
	}
}